﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RealtyManagementSystem.DAL;

namespace RealtyManagementSystem.BLL
{
    public class AnnouncementsProvider : IDisposable
    {
        private realtydbEntities _realtyContext = null;

        public AnnouncementsProvider()
        {
            _realtyContext = new realtydbEntities();
        }

        public Announcement Add(DAL.Announcement announcement)
        {
            _realtyContext.AddToAnnouncements(announcement);
            _realtyContext.SaveChanges();
            return announcement;
        }

        public Announcement GetById(int aId)
        {
            return (from ann in _realtyContext.Announcements.Include("aspnet_Users")
                    where ann.AnnounceId == aId
                    select ann).SingleOrDefault();
        }

        #region Dispose

        private bool disposedValue = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposedValue)
            {
                if (disposing)
                {
                    _realtyContext.Dispose();
                }
            }
            this.disposedValue = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        #endregion Dispose
    }//class
}